using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class TimedVehicleDestroyEvent : VehicleDestroyEvent, ITimedEvent
{
	public int neededVehicleDestroy;

	public float neededTime;

	public bool disableIfAchieved = true;

	[HideInInspector]
	public bool achieved;

	public bool IfEvent(VehicleDestroyInfo newDestroy, List<VehicleDestroyInfo> vehicleDestroyList)
	{
		if (!achieved)
		{
			int num = 1;
			if (neededPrivateCar)
			{
				if (newDestroy.privateCar)
				{
					if (neededTank)
					{
						if (newDestroy.isTank)
						{
							foreach (VehicleDestroyInfo vehicleDestroy in vehicleDestroyList)
							{
								if (vehicleDestroy.privateCar && vehicleDestroy.isTank && newDestroy.time - vehicleDestroy.time <= neededTime)
								{
									num++;
									if (num == neededVehicleDestroy)
									{
										return true;
									}
								}
							}
						}
					}
					else if (!newDestroy.isTank)
					{
						foreach (VehicleDestroyInfo vehicleDestroy2 in vehicleDestroyList)
						{
							if (vehicleDestroy2.privateCar && !vehicleDestroy2.isTank && newDestroy.time - vehicleDestroy2.time <= neededTime)
							{
								num++;
								if (num == neededVehicleDestroy)
								{
									return true;
								}
							}
						}
					}
				}
			}
			else if (!newDestroy.privateCar)
			{
				foreach (VehicleDestroyInfo vehicleDestroy3 in vehicleDestroyList)
				{
					if (!vehicleDestroy3.privateCar && newDestroy.time - vehicleDestroy3.time <= neededTime)
					{
						num++;
						if (num == neededVehicleDestroy)
						{
							return true;
						}
					}
				}
			}
		}
		return false;
	}

	public IEnumerator DisableForTime()
	{
		AddToAchidedList();
		if (disableIfAchieved)
		{
			achieved = true;
		}
		yield return new WaitForSeconds(neededTime);
		Reset();
	}

	public void AddToAchidedList()
	{
		GameplayEventsManager.instance.allTimedEvents.Add(this);
		BCWDebug.Log("allTimedEvents.Count = " + GameplayEventsManager.instance.allTimedEvents.Count + "    WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
	}

	public void Reset()
	{
		achieved = false;
	}
}
